package pri.damai.xiaowu.anydoor.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import pri.damai.xiaowu.anydoor.business.BaseModel;
import pri.damai.xiaowu.anydoor.util.BizCodecUtils;

/**
 * web socket frame 处理器
 *
 * @description
 * @author YangXinFu
 * @date 8:54 2022/8/8
 **/
@ChannelHandler.Sharable
@Component
@Slf4j
public class WebSocketFrameHandler extends SimpleChannelInboundHandler<BinaryWebSocketFrame> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, BinaryWebSocketFrame frame) throws Exception {
        ByteBuf content = frame.content();
        BaseModel model = BizCodecUtils.decode(content);
        model.process(ctx);
    }
}
